home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-11-12 | 5.4 KB | 221 lines | [TEXT/PJMM] |
- unit UExampleDlog;
-
- { This unit contains CExampleDlog, a simple descendant of CDlog. The dialog }
- { includes three text fields, an OK button, a Cancel button, an ICON, a picture }
- { item that changes appearance when you click it, a group of three radio buttons,}
- { and three titled borders. }
- {}
- { The OK button is disabled until there is a non-null entry in the 'Numeric Text' }
- { field. }
- {}
- interface
-
- uses
- Script, TCL, {}
- CDlog;
-
- type
- { -------------------------------------------------------------------- }
- { CExampleDlog}
- {}
- { A CDlog descendant that implements an example dialog.}
- {}
- { SUPERCLASS = CDlog}
- { SUBCLASSES = None}
- { -------------------------------------------------------------------- }
- CExampleDlog = object(CDlog)
-
- procedure IExampleDlog; { Initialize }
-
- procedure DoCommand ( { Handle commands }
- theCommand: longint); { Command number }
- override;
-
- procedure SetOKButton; { Set Ok button }
- end;
-
- procedure DoExampleDlog;
-
- implementation
-
- const
-
- {Commands}
- cmdRadio1 = 2401;
- cmdRadio2 = 2402;
- cmdRadio3 = 2403;
- cmdEditNumber = 2404;
-
- {Items in example dialog}
- iLabel1 = 3;
- iLabel2 = 4;
- iSomeText = 5;
- iNumericText = 6;
- iMoreText = 7;
- iLabel3 = 8;
-
- iIcon = 12;
- iPicture = 13;
- iUser = 14;
-
- {Picture IDs}
- kPictOne = 10241;
- kPictTwo = 10242;
-
- {Constants for use with controls}
- kActive = 0;
- kInActive = 255;
-
- {Misc}
- BORDER_OFFSET = 3;
-
- kExampleDlog = 1024;
-
- procedure DoExampleDlog;
- var
- theDlog: CExampleDlog;
-
- begin
- new(theDlog);
- if theDlog <> nil then
- theDlog.IExampleDlog;
- end;
-
- { -------------------------------------------------------------------- }
- { C E x a m p l e D l o g M e t h o d s }
- { -------------------------------------------------------------------- }
- { IExampleDlog}
- {}
- { Initialize the example Dialog.}
- { -------------------------------------------------------------------- }
- procedure CExampleDlog.IExampleDlog;
- var
- wRadioGroup: CDRadioGroup;
- wBorder: CTitledBorder;
- wFontInfo: FontInfo;
- wLineHeight: integer;
- wFrame: Rect;
-
- begin
- IDlog(kExampleDlog, FALSE, nil, gApplication, systemFont, 12);
- CDlogWind(itsWindow).SetModal(TRUE);
-
- { Get font info for use creating borders }
- GetFontInfo(wFontInfo);
- with wFontInfo do
- wLineHeight := ascent + descent + leading;
-
- { Create borders }
- SectPanes(itsPanes, iLabel1, iLabel3, wFrame);
- InsetRect(wFrame, -BORDER_OFFSET, -BORDER_OFFSET);
-
- {Another adjustment to the border is necessary... the bottom,right item is}
- {an editText item, and the pane in the 'itsPanes' list does not include the}
- {outline. So, add BORDER_OFFSET to bottom and right.}
- with wFrame do begin
- bottom := bottom + BORDER_OFFSET;
- right := right + BORDER_OFFSET;
- end;
-
- New(wBorder);
- with wFrame do
- wBorder.ITitledBorder(itsWindow, SELF, right - left, wLineHeight + (bottom - top), left, top - wLineHeight, sizFIXEDLEFT, sizFIXEDTOP, 'Text Fields:');
- itsWindow.itsSubviews.BringFront(wBorder);
-
- {Give radio group same borderwidth as bordered items above it}
- wRadioGroup := CDRadioGroup(itsRadioGroups.FirstItem);
- wRadioGroup.SetBorderTitle('Radio Buttons:');
- with wFrame do
- wRadioGroup.CalcBorder(right - left, 0);
-
- SectPanes(itsPanes, iIcon, iUser, wFrame);
- InsetRect(wFrame, -BORDER_OFFSET, -BORDER_OFFSET);
- New(wBorder);
- with wFrame do
- wBorder.ITitledBorder(itsWindow, SELF, right - left, wLineHeight + (bottom - top), left, top - wLineHeight, sizFIXEDLEFT, sizFIXEDTOP, 'Graphic Items:');
- itsWindow.itsSubviews.BringFront(wBorder);
-
- SetEdit(iSomeText, CdLenFiltOn, 8);
- SetEdit(iNumericText, CdNumFiltOn + CdLenFiltOn, 3);
- SetEdit(iMoreText, CdLenFiltOn, 4);
-
- CDEditText(itsPanes.NthItem(iNumericText)).SetClickCmd(cmdEditNumber);
-
- SetOKButton;
-
- {Set command for picture item; if clicked, the picture changes}
- CDPicture(itsPanes.NthItem(iPicture)).SetClickCmd(kPictTwo);
-
- itsWindow.Select;
- end;
-
- { -------------------------------------------------------------------- }
- { DoCommand}
- {}
- { Handles activity associated with dialog items. }
- { -------------------------------------------------------------------- }
- procedure CExampleDlog.DoCommand (theCommand: longint);
- var
- wGraphic: CDGraphic;
-
- begin
- case theCommand of
- cmdOK:
- begin
- CloseWind(itsWindow);
- end;
-
- cmdCancel:
- begin
- CloseWind(itsWindow);
- end;
-
- cmdRadio1, cmdRadio2, cmdRadio3:
- begin
- CDRadioGroup(itsRadioGroups.NthItem(1)).SetStationID(theCommand - 2400);
- end;
-
- cmdEditNumber:
- SetOkButton;
-
- kPictOne:
- begin
- CDPicture(itsPanes.NthItem(iPicture)).NewPicture(kPictOne);
- CDPicture(itsPanes.NthItem(iPicture)).SetClickCmd(kPictTwo);
- end;
-
- kPictTwo:
- begin
- CDPicture(itsPanes.NthItem(iPicture)).NewPicture(kPictTwo);
- CDPicture(itsPanes.NthItem(iPicture)).SetClickCmd(kPictOne);
- end;
-
- cmdBadChar:
- SysBeep(1);
-
- cmdBadLength:
- SysBeep(1);
-
- otherwise
- inherited DoCommand(theCommand);
- end; {case}
- end; {DoCommand}
-
- { -------------------------------------------------------------------- }
- { SetOKButton}
- {}
- { Sets the OK button active or inactive based on the prerequisite items. }
- { -------------------------------------------------------------------- }
- procedure CExampleDlog.SetOKButton;
- var
- theString: Str255;
-
- begin
- GetIText(iNumericText, theString);
- if Length(theString) > 0 then
- CDControl(itsPanes.NthItem(1)).Hilite(kActive)
- else
- CDControl(itsPanes.NthItem(1)).Hilite(kInActive);
- end;
-
- end.